import App from "./App.vue";
import router from "./router";
import { setupStore } from "@/store";
import { getPlatformConfig } from "./config";
import { MotionPlugin } from "@vueuse/motion";
// import { useEcharts } from "@/plugins/echarts";
import { createApp, type Directive } from "vue";
import { useElementPlus } from "@/plugins/elementPlus";
import { injectResponsiveStorage } from "@/utils/responsive";
import { closeLoading, loading } from "@/utils/message";
import Table from "@pureadmin/table";
// import PureDescriptions from "@pureadmin/descriptions";

// 引入重置样式
import "./style/reset.scss";
// 导入公共样式
import "./style/index.scss";
// 一定要在main.ts中导入tailwind.css，防止vite每次hmr都会请求src/style/index.scss整体css文件导致热更新慢的问题
import "./style/tailwind.css";
import "element-plus/dist/index.css";
// 导入字体图标
import "./assets/iconfont/iconfont.js";
import "./assets/iconfont/iconfont.css";

import VxeUI from "vxe-pc-ui";
import "vxe-pc-ui/lib/style.css";
// ...纯表格
import VxeTable from "vxe-table";
import "vxe-table/lib/style.css";

import VxeUIPluginRenderElement from "@vxe-ui/plugin-render-element";
import "@vxe-ui/plugin-render-element/dist/style.css";
import microApp from "@micro-zoe/micro-app";

VxeUI.use(VxeUIPluginRenderElement);

const app = createApp(App);

// 自定义指令
import * as directives from "@/directives";
Object.keys(directives).forEach(key => {
  app.directive(key, (directives as { [key: string]: Directive })[key]);
});

VxeTable.setConfig({
  // loadingText: null,
  table: {
    // size: "mini",
    border: true,
    showOverflow: true,
    align: "left",
    loadingConfig: {
      icon: "vxe-icon-indicator roll"
      // text: "正在拼命加载中..."
    }
  },
  modal: {
    minHeight: 200
  },
  pager: {
    pagerCount: 7,
    pageSizes: [50, 100, 200, 500],
    layouts: [
      "PrevJump",
      "PrevPage",
      "JumpNumber",
      "NextPage",
      "NextJump",
      "Sizes",
      "FullJump",
      "Total"
    ],
    align: "right",
    background: true
  },
  grid: {
    size: null,
    zoomConfig: {
      escRestore: true
    },
    pagerConfig: {},
    toolbarConfig: {},
    proxyConfig: {
      props: {
        result: "records",
        total: "total"
      }
    }
  }
});

// 全局注册@iconify/vue图标库
import {
  IconifyIconOffline,
  IconifyIconOnline,
  FontIcon
} from "./components/ReIcon";
app.component("IconifyIconOffline", IconifyIconOffline);
app.component("IconifyIconOnline", IconifyIconOnline);
app.component("FontIcon", FontIcon);

// 全局注册按钮级别权限组件
import { Auth } from "@/components/ReAuth";
app.component("Auth", Auth);

// 全局注册vue-tippy
import "tippy.js/dist/tippy.css";
import "tippy.js/themes/light.css";
import VueTippy from "vue-tippy";
app.use(VueTippy);

getPlatformConfig(app).then(async config => {
  setupStore(app);
  app.use(router);
  app.use(VxeUI);
  app.use(VxeTable);
  await router.isReady();
  injectResponsiveStorage(app, config);
  app.use(MotionPlugin).use(useElementPlus).use(Table);
  // .use(PureDescriptions)
  // .use(useEcharts);
  app.mount("#app");
});

microApp.start({
  lifeCycles: {
    created() {
      loading();
      console.log("created 全局监听");
    },
    beforemount() {
      console.log("beforemount 全局监听");
    },
    mounted() {
      closeLoading();
      console.log("mounted 全局监听");
    },
    unmount() {
      console.log("unmount 全局监听");
    },
    error() {
      closeLoading();
      console.log("error 全局监听");
    }
  }
});
